#!/usr/bin/env python3
"""
Mask phone numbers and emails in text.
Usage: python3 desensitize.py [input_file] > masked.txt
Reads stdin if no input file is provided.
"""
import sys, re

def mask(text: str) -> str:
    text = re.sub(r'(\b1[3-9]\d{1})\d{4}(\d{4}\b)', r'\1****\2', text)
    text = re.sub(r'([A-Za-z0-9._%+-])[A-Za-z0-9._%+-]*(@[A-Za-z0-9.-]+\.[A-Za-z]{2,})', r'\1***\2', text)
    return text

if __name__ == '__main__':
    data = sys.stdin.read() if len(sys.argv) < 2 else open(sys.argv[1], 'r', encoding='utf-8', errors='ignore').read()
    sys.stdout.write(mask(data))
